<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    var removeDuplicates = function(s, k) {
        let arr = s.split('')
        fun(arr, k)
        return arr.join('')
    };

    const fun = (arr, k) => {
        if(arr.length === 0) return ''
        console.log(arr);
        let i  = 0
        while(i < arr.length) {
            const owner = arr.slice(i, i + k).some(v => v !== arr[i])
            if(owner) {
                i++
            } else {
                arr.splice(i, k)
                fun(arr, k)
                return
            }
        }
    }
    console.log(removeDuplicates('deeedbbcccbdaa', 3));
    
  </script>
</body>
</html>